﻿using System;
using System.Configuration;
using System.Web.Mvc;
using Taobao.Top.Api;
using Taobao.Top.Api.Request;

namespace TopManagement.Controllers
{
    public class TradeOrdersController : Controller
    {
        public ActionResult Index()
        {
            //http://my.open.taobao.com/auth/authorize.htm?appkey=21219538
            // http://container.open.taobao.com/container?appkey=21219538
            //沙箱Appkey 1021219538  sandbox_c_20 taobao1234
            //http://container.api.tbsandbox.com/container?appkey=1021219538
            //沙箱容器地址http://container.api.tbsandbox.com/container 
            //沙箱接口访问地址http://gw.api.tbsandbox.com/router/rest 

            string sessionKey = Request.QueryString["top_session"];
            string appKey = ConfigurationManager.AppSettings["AppKey"];
            string appSecret = ConfigurationManager.AppSettings["AppSecret"];
            //TopXmlRestClient client = new TopXmlRestClient("http://gw.api.tbsandbox.com/router/rest", appKey, appSecret);
            //SessionKey :TOP-10f0acc04ea9d969c560f2a2575207b135HYz0WtqcGCWDRezEjtXKomMXhJCb4w-END
            /// 得到单个用户信息(taobao.user.get)
            //DynamicTopRequest req = new DynamicTopRequest("taobao.user.get");
            //req.AddTextParameter("fields", "user_id,nick,sex,buyer_credit,seller_credit,location.country,created,last_visit,location.zip,birthday,type,has_more_pic,item_img_num,item_img_size,prop_img_num,prop_img_size,auto_repost,promoted_type,status,alipay_bind,consumer_protection");
            //req.AddTextParameter("nick", "sandbox_c_1");

            //string rsp = client.GetResponse(req);
            //Console.WriteLine(rsp);

            TopXmlRestClient client = new TopXmlRestClient("http://gw.api.tbsandbox.com/router/rest", appKey, appSecret);
            //TopXmlRestClient client = new TopXmlRestClient("http://gw.api.taobao.com/router/rest", appKey, appSecret);
            /// 搜索当前会话用户作为卖家已卖出的交易数据(taobao.trades.sold.get)
            DynamicTopRequest req = new DynamicTopRequest("taobao.trades.sold.get");
            req.AddTextParameter("fields", "seller_nick,buyer_nick,title,type,refund_status,created,iid,price,pic_path,num,tid,buyer_message,sid,shipping_type,alipay_no,payment,discount_fee,adjust_fee,snapshot_url,status,seller_rate,buyer_rate,buyer_memo,seller_memo,pay_time,end_time,modified,buyer_obtain_point_fee,point_fee,real_point_fee,total_fee,post_fee,buyer_alipay_no,receiver_name,receiver_state,receiver_city,receiver_district,receiver_address,receiver_zip,receiver_mobile,receiver_phone,consign_time,buyer_email,commission_fee,seller_alipay_no,seller_mobile,seller_phone,seller_name,seller_email,available_confirm_fee,has_postFee,received_payment,cod_fee,timeout_action_time,orders,sku_id,sku_properties_name,item_meal_name,outer_iid,outer_sku_id");
            req.AddTextParameter("start_created", "2012-09-14 22:47:53");
            req.AddTextParameter("end_created", "2012-09-27 22:47:59");

            string rsp = client.GetResponse(req, sessionKey);
            Console.WriteLine(rsp);

            ViewData["test"] = rsp;
            
            return View();
        }

    }
}
